home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef __ISINGLETON_H__
- #define __ISINGLETON_H__
- /*
- Peon - Win32 Games Programming Library
- Copyright (C) 2002-2005 Erik Yuzwa
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this library; if not, write to the Free
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- Erik Yuzwa
- peon AT wazooinc DOT com
- */
-
- /* Original version Copyright (C) Scott Bilas, 2000.
- * All rights reserved worldwide.
- *
- * This software is provided "as is" without express or implied
- * warranties. You may freely copy and compile this source into
- * applications you distribute provided that the copyright text
- * below is included in the resulting source code, for example:
- * "Portions Copyright (C) Scott Bilas, 2000"
- */
-
- #include "Peonstdafx.h"
-
- namespace peon
- {
-
- /**
- * Template class for creating single-instance global classes.
- * The code in this file is taken from article 1.3 in the the book:
- * Game Programming Gems from Charles River Media with the
- * copyright notice going to Scott Bilas.
- */
- template <typename T> class PEONMAIN_API ISingleton
- {
- protected:
-
- /** The static member object */
- static T* ms_Singleton;
-
- public:
- /**
- * Constructor
- */
- ISingleton( void )
- {
- assert( !ms_Singleton );
- ms_Singleton = static_cast< T* >( this );
- }
-
- /**
- * Destructor
- */
- ~ISingleton( void )
- { assert( ms_Singleton ); ms_Singleton = 0; }
-
- /**
- * This method just returns the internal member by
- * reference
- * @return T& - reference to internal abstract Type
- */
- static T& getSingleton( void )
- { assert( ms_Singleton ); return ( *ms_Singleton ); }
-
- /**
- * This method just returns the internal member by
- * a pointer
- * @return T* - pointer to the internal abstract Type
- */
- static T* getSingletonPtr( void )
- { return ms_Singleton; }
- };
- }
-
- #endif
-